﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using WJSHWebApi.DBModel;
using WJSHWebApi.InterFace;
using System.Linq;

namespace WJSHWebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FCCache : ControllerBase
    {
        private IDBInterface iDBInterface;
        public FCCache(IDBInterface dBInterface)
        {
            iDBInterface = dBInterface;
        }
        // GET: api/<Rawfoilmachine>
        [HttpGet]
        public IEnumerable<FCCache_Entity> Get()
        {
            return iDBInterface.Where<FCCache_Entity>(x => x.IsEnable == true && x.IsHave==true && x.IsCreat==false).ToList();
        }
        [HttpPost]
        public bool Updata(FCCache_Entity detectCache_Entity)
        {
            detectCache_Entity.IsHave = false;
            return iDBInterface.Update<FCCache_Entity>(detectCache_Entity);
        }


        [HttpGet]
        public FCCache_Entity GetFCCache_EntityByRemark(string Remark)
        {

            return iDBInterface.FirstOrDefault<FCCache_Entity>(X => X.IsEnable == true && X.IsCreat == false && X.Remark == Remark);
        }

        [HttpGet]
        public bool UpdataNoHave(string Remark)
        {
            var FCCache_Entity = iDBInterface.FirstOrDefault<FCCache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.Remark == Remark);
            FCCache_Entity.IsHave = false;
            return iDBInterface.Update(FCCache_Entity);
        }
        [HttpGet]
        public bool UpdataHave(string Remark)
        {
            var FCCache_Entity = iDBInterface.FirstOrDefault<FCCache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.Remark == Remark);
            FCCache_Entity.IsHave = true;
            return iDBInterface.Update(FCCache_Entity);
        }
    }
}
